package com.spring.format.code.generation.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.spring.format.code.generation.constants.Constants;
import com.spring.format.code.generation.constants.FileNameConstants;
import com.spring.format.code.generation.constants.FileNameEnumType;

/**
 * 生成 po，vo等名字帮助类
 * 
 * @author lenovo
 *
 */
public class PathUtil {
	/**
	 * 日志
	 */
	private static Logger log = LoggerFactory.getLogger(PathUtil.class);

	/**
	 * 生成文件 package路径
	 * 
	 * @param table_name
	 * @param nameType
	 * @return
	 */
	public static String createPackagePath(String table_name, FileNameEnumType nameType) {
		// 系统路径公用部分
		String package_path = PropertiesUtil.getValue(Constants.PACKAGE_PATH);
		package_path = (null == package_path) ? Constants.PATH : package_path;
		// 路径变量
		StringBuilder name = new StringBuilder();
		name.append(package_path);
		// 生成完成路径
		switch (nameType.toString()) {
		case FileNameConstants.PO_NAME:
			name.append(Constants.PATH_PO).append(";\n");
			break;
		case FileNameConstants.VO_NAME:
			name.append(Constants.PATH_VO).append(";\n");
			break;
		case FileNameConstants.FORM_NAME:
			name.append(Constants.PATH_FORM).append(";\n");
			break;
		case FileNameConstants.DAO_API_NAME:
			name.append(Constants.PATH_DAO_API).append(";\n");
			break;
		case FileNameConstants.SERVICE_NAME:
			name.append(Constants.PATH_SERVICE).append(";\n");
			break;
		case FileNameConstants.SERVICE_API_NAME:
			name.append(Constants.PATH_SERVICE_API).append(";\n");
			break;
		case FileNameConstants.BIZ_NAME:
			name.append(Constants.PATH_BIZ).append(";\n");
			break;
		case FileNameConstants.BIZ_API_NAME:
			name.append(Constants.PATH_BIZ_API).append(";\n");
			break;
		case FileNameConstants.CONTROLLER_NAME:
			name.append(Constants.PATH_CONTROLLER).append(";\n");
			break;
		case FileNameConstants.MAPPER_NAME:
			name.append(Constants.PATH_MAPPER);
			break;
		case FileNameConstants.WEB_SERVICE_NAME:
			name.append(Constants.PATH_WEB_SERVICE).append(";\n");
			break;
		case FileNameConstants.WEB_SERVICE_API_NAME:
			name.append(Constants.PATH_WEB_API_SERVICE).append(";\n");
			break;
		case FileNameConstants.ACTION_NAME:
			name.append(Constants.PATH_ACTION).append(";\n");
			break;
		default:
			break;
		}
		log.debug(" import文件路径：{}", name.toString());
		return name.toString();
	}

	/**
	 * 生成文件 import 引入路径
	 * 
	 * @param table_name
	 * @param nameType
	 * @return
	 */
	public static String createImportPath(String table_name, FileNameEnumType nameType) {
		// 系统路径公用部分
		String package_path = PropertiesUtil.getValue(Constants.PACKAGE_PATH);
		package_path = (null == package_path) ? Constants.PATH : package_path;
		// 路径变量
		StringBuilder name = new StringBuilder();
		name.append(package_path);
		// 生成完成路径
		switch (nameType.toString()) {
		case FileNameConstants.PO_NAME:
			name.append(Constants.PATH_PO).append(".")
					.append(NameUtil.createFileName(table_name, FileNameEnumType.PO_NAME));
			break;
		case FileNameConstants.VO_NAME:
			name.append(Constants.PATH_VO).append(".")
					.append(NameUtil.createFileName(table_name, FileNameEnumType.VO_NAME));
			break;
		case FileNameConstants.FORM_NAME:
			name.append(Constants.PATH_FORM).append(".")
					.append(NameUtil.createFileName(table_name, FileNameEnumType.FORM_NAME));
			break;
		case FileNameConstants.DAO_API_NAME:
			name.append(Constants.PATH_DAO_API).append(".")
					.append(NameUtil.createFileName(table_name, FileNameEnumType.DAO_API_NAME));
			break;
		case FileNameConstants.SERVICE_NAME:
			name.append(Constants.PATH_SERVICE).append(".")
					.append(NameUtil.createFileName(table_name, FileNameEnumType.SERVICE_NAME));
			break;
		case FileNameConstants.SERVICE_API_NAME:
			name.append(Constants.PATH_SERVICE_API).append(".")
					.append(NameUtil.createFileName(table_name, FileNameEnumType.SERVICE_API_NAME));
			break;
		case FileNameConstants.BIZ_NAME:
			name.append(Constants.PATH_BIZ).append(".")
					.append(NameUtil.createFileName(table_name, FileNameEnumType.BIZ_NAME));
			break;
		case FileNameConstants.BIZ_API_NAME:
			name.append(Constants.PATH_BIZ_API).append(".")
					.append(NameUtil.createFileName(table_name, FileNameEnumType.BIZ_API_NAME));
			break;
		case FileNameConstants.CONTROLLER_NAME:
			name.append(Constants.PATH_CONTROLLER).append(".")
					.append(NameUtil.createFileName(table_name, FileNameEnumType.CONTROLLER_NAME));
			break;
		case FileNameConstants.MAPPER_NAME:
			name.append(Constants.PATH_MAPPER).append(".")
					.append(NameUtil.createFileName(table_name, FileNameEnumType.MAPPER_NAME));
			break;

		}
		log.debug(" import文件路径：{}", name.toString());
		return name.toString();
	}

	/**
	 * 生成文件 import 引入路径
	 * 
	 * @param table_name
	 * @param nameType
	 * @return
	 */
	public static String createImportClassPath(String table_name, FileNameEnumType nameType) {
		// 系统路径公用部分
		String package_path = PropertiesUtil.getValue(Constants.PACKAGE_PATH);
		package_path = (null == package_path) ? Constants.PATH : package_path;
		// 路径变量
		StringBuilder importStr = new StringBuilder();
		importStr.append(" import ").append(package_path);
		// 生成完成路径
		switch (nameType.toString()) {
		case FileNameConstants.PO_NAME:
			importStr.append(Constants.PATH_PO).append(".")
					.append(NameUtil.createFileName(table_name, FileNameEnumType.PO_NAME));
			break;
		case FileNameConstants.VO_NAME:
			importStr.append(Constants.PATH_VO).append(".")
					.append(NameUtil.createFileName(table_name, FileNameEnumType.VO_NAME));
			break;
		case FileNameConstants.FORM_NAME:
			importStr.append(Constants.PATH_FORM).append(".")
					.append(NameUtil.createFileName(table_name, FileNameEnumType.FORM_NAME));
			break;
		case FileNameConstants.DAO_API_NAME:
			importStr.append(Constants.PATH_DAO_API).append(".")
					.append(NameUtil.createFileName(table_name, FileNameEnumType.DAO_API_NAME));
			break;
		case FileNameConstants.SERVICE_NAME:
			importStr.append(Constants.PATH_SERVICE).append(".")
					.append(NameUtil.createFileName(table_name, FileNameEnumType.SERVICE_NAME));
			break;
		case FileNameConstants.SERVICE_API_NAME:
			importStr.append(Constants.PATH_SERVICE_API).append(".")
					.append(NameUtil.createFileName(table_name, FileNameEnumType.SERVICE_API_NAME));
			break;
		case FileNameConstants.BIZ_NAME:
			importStr.append(Constants.PATH_BIZ).append(".")
					.append(NameUtil.createFileName(table_name, FileNameEnumType.BIZ_NAME));
			break;
		case FileNameConstants.BIZ_API_NAME:
			importStr.append(Constants.PATH_BIZ_API).append(".")
					.append(NameUtil.createFileName(table_name, FileNameEnumType.BIZ_API_NAME));
			break;
		case FileNameConstants.CONTROLLER_NAME:
			importStr.append(Constants.PATH_CONTROLLER).append(".")
					.append(NameUtil.createFileName(table_name, FileNameEnumType.CONTROLLER_NAME));
			break;
		case FileNameConstants.MAPPER_NAME:
			importStr.append(Constants.PATH_MAPPER).append(".")
					.append(NameUtil.createFileName(table_name, FileNameEnumType.MAPPER_NAME));
			break;
		case FileNameConstants.WEB_SERVICE_API_NAME:
			importStr.append(Constants.PATH_WEB_API_SERVICE).append(".")
					.append(NameUtil.createFileName(table_name, FileNameEnumType.WEB_SERVICE_API_NAME));
			break;
		default:break;
		}
		importStr.append(";\n");
		log.debug(" import文件路径：{}", importStr.toString());
		return importStr.toString();
	}

}
